package cn.wolfcode.luowowo.website.web.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.HotelDetail;
import cn.wolfcode.luowowo.article.domain.HotelTheme;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IHotelDetailService;
import cn.wolfcode.luowowo.article.service.IHotelThemeService;
import cn.wolfcode.luowowo.scenic.domain.Scenic;
import cn.wolfcode.luowowo.scenic.service.IScenicService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/hotel")
public class HotelController {
    @Reference
    private IDestinationService destinationService;
    @Reference
    private IHotelThemeService hotelThemeService;
    @Reference
    private IScenicService scenicService;
    @Reference
    private IHotelDetailService hotelDetailService;
    @RequestMapping("")
    public String hotel(Model model){
        //查询酒店国内的出行目的地
        List<Destination> dests = destinationService.selectHotelChTop20();
        model.addAttribute("dests",dests);
        //查询酒店国外的出行目的地
        List<Destination> overseas = destinationService.selectHotelAbTop20();
        model.addAttribute("overseas",overseas);
        //   主题住宿    其中第二个  周末好去处    为景点
        List<HotelTheme> hotelThemes = hotelThemeService.selectList();
        for(HotelTheme ht:hotelThemes){
            if(!"周末好去处".equals(ht.getName())){
                continue;
            }
            List<Object> list = new ArrayList<>();
            for(long id:ht.getDestIds()){
                Scenic scenic = scenicService.getById(id);
                list.add(scenic);
            }
            ht.setDests(list);
        }
        model.addAttribute("hotelThemes",hotelThemes);
        //特价酒店
        List<HotelDetail> hotelDetails = hotelDetailService.selectHDTop(6);
        model.addAttribute("hotelDetails",hotelDetails);
        return "/hotelPage/hotel";
    }
    @RequestMapping("/theme")
    public String theme(Model model,Long id){
        HotelTheme ht = hotelThemeService.getById(id);
        if(!"周末好去处".equals(ht.getName())){
            model.addAttribute("list",ht.getDests());
            return "/hotelPage/hotelTpl";
        }
        List<Object> list = new ArrayList<>();
        for(long sid:ht.getDestIds()){
            Scenic scenic = scenicService.getById(sid);
            String coverUrl = scenic.getCoverUrl();
            String[] split = coverUrl.split(";");
            scenic.setDiaomao(split[0]);
            list.add(scenic);
        }
        ht.setDests(list);
        model.addAttribute("list",ht.getDests());
        return "/hotelPage/hotelTpl";
    }
    @RequestMapping("/detail")
    public String detail(Model model,Long id){
        List<HotelDetail> hds = hotelDetailService.selectByDid(id);
        model.addAttribute("hds",hds);
        return "/hotelPage/hotelTpl1";
    }
    @RequestMapping("/reserve")
    public String reserve(Model model,Long id){
        //不干了！！！！！！！
        return "/hotelPage/dingjiudian";
    }
}
